//
//  ScanCodeManager.m
//  ThunderChat
//
//  Created by Kelly xu on 2019/1/2.
//  Copyright © 2019 Simubang. All rights reserved.
//

#import "ScanCodeManager.h"
#import "ScanCodeViewController.h"
@interface ScanCodeManager(){
    
}
@end
@implementation ScanCodeManager
+(ScanCodeManager*)shardManager{
    static ScanCodeManager *shardManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shardManager = [[ScanCodeManager alloc] init];
    });
    return shardManager;
}
-(void)showScanCode:(void(^)(NSString *sn))suc fail:(void(^)())fail{
    ScanCodeViewController *scanVc = [[ScanCodeViewController alloc] initWithFinish:^(NSString *result, NSError *error) {
        if (error) {
            NSLog(@"error: %@",error);
            fail();
        } else {
            NSLog(@"扫描结果：%@",result);
            NSString *str = [NSString stringWithFormat:@"%@",result];
//            NSArray *array = [str componentsSeparatedByString:@","];
//            if (array.count > 0) {
//                suc(array[0]);
//            }else{
//                Toast(@"扫描失败");
//                fail();
//            }
            suc(str);
            
        }
    }];
    [KeyWindow.rootViewController.rt_navigationController pushViewController:scanVc animated:YES complete:nil];
}
@end
